/**
 * Copyright (c) 2018, Alex. All rights reserved.
 */
package com.oschina.bottle.poi;

import java.lang.reflect.Method;

/**
 * 表头标题
 *
 * @author <a href="mailto:zhongchao@gegejia.com">zhong</a>
 * @version 1.0 2018/1/23
 * @since 1.0
 */
public class Head {

    /**
     * 列号
     */
    private int index;

    /**
     * 文件表头标题
     */
    private String columnName;

    /**
     * 映射实体字段名
     */
    private String fieldName;

    /**
     * 字段的类型
     */
    private Class<?> fieldClass;

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public Class<?> getFieldClass() {
        return fieldClass;
    }

    public void setFieldClass(Class<?> fieldClass) {
        this.fieldClass = fieldClass;
    }

    public Object convertType(String value) {
        if(!String.class.equals(fieldClass)) {
            try {
                Method method = fieldClass.getMethod("valueOf", String.class);
                return method.invoke(null, value);
            } catch (Exception ignored) {
            }
        }
        return value;
    }
}
